<%
# Code Review plugin for Redmine
# Copyright (C) 2009  Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-%>
<div class="code-review-dialog">
<div class="code-review-form-title drag-handle" >
  <table border="0" width="100%" class="header_table">
    <tr>
      <%
         if (@review.is_closed?)
           image_class = 'icon-closed-review'
         else
           image_class = 'icon-review'
         end
      -%>
      <td><span class="icon <%= image_class%>"><%=h l(:code_review) %> 
          <%= link_to '#' + @review.issue.id.to_s, :controller => 'issues', :action => 'show',
               :id => @review.issue.id %>
        </span></td>
      <td align="right">
        <%= link_to_function image_tag('close.png'), "$('show_review_#{@review.id}').hide();" %>
      </td>
    </tr>
  </table>
</div>

<div class="code_review_body">
  <div class="code_review_body-scrollarea">
    <%= error_messages_for 'review' -%>
    <%= error_messages_for 'reply' -%>
    <% if @notice -%>
      <div class="flash notice"><%= @notice -%></div>
    <% end -%>
    <% if @error -%>
      <div class="flash error"><%= @error -%></div>
    <% end -%>
<div class="code_review_viewer issue">
<div class="contextual">
  <% if authorize_for('code_review', 'update') -%>
      <%= link_to_function  l(:button_update), "$('update-form-#{@review.id}').show();return false;", :class => 'icon icon-edit' %>
  <% end %>
<% if authorize_for('code_review', 'destroy') -%>
<%= link_to_remote(l(:button_delete), :update => "show_review_#{@review.id}",
  :url => {:controller => 'code_review', :action => 'destroy', :id => @project, :review_id => @review},
  :confirm => l(:text_are_you_sure),
  :success => "deleteReview(#{@review.id})",
  :html => {:class => 'icon icon-del'}) %>
<% end -%>
</div>
  <h2>
    <%= l(:label_line_number, @review.line) %>:
    <%=h @review.subject%>
  </h2>
 
<p class="author">
  <%= avatar(@review.user, :size => "64") %>
        <%= authoring @review.created_at, @review.user %>.
        <%= l(:label_updated_time, distance_of_time_in_words(Time.now, @review.updated_at)) + '.' if @review.created_at != @review.updated_at %>
</p>


<table>
<tr>
    <td style="width:20%; white-space:nowrap;" class="status"><b><%=h l(:field_status) %>:</b>
    </td>
    <td><%=h @review.issue.status %></td>

</tr>
 </table>
 
<hr/>
  <div class="wiki">
<%= textilizable @review, :comment %>
  </div>
  <div class="box" id="update-form-<%= @review.id %>" style="display:none;">

<% remote_form_for :review, @review,
  :url => {:controller => 'code_review', :action => 'update', :id=>@project, :review_id => @review.id},
  :update => "show_review_#{@review.id}" do |f|  %>
<%= f.hidden_field :lock_version %>
<%= hidden_field :issue,  :lock_version%>
    <p>
      <label><b>
        <%=h l(:field_subject)%>:
        </b></label>
      <%= f.text_field :subject, :size => 70, :value => @review.subject%>
    </p>

      <% if @allowed_statuses and @allowed_statuses.any? %>
    <p>
      <label>
        <b><%=h l(:field_status)%>:</b>
      </label>
<%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
<% end %>
    
<p>
  <%= f.text_area :comment,
                   :cols => 30,
                   :rows => 10,
                   :accesskey => accesskey(:edit),
                   :class => 'wiki-edit',
                   :id => 'review_comment_' + @review.id.to_s%>

</p>
<p>
      <%= submit_tag l(:button_apply) %>
      <input type="button" value="<%=h l(:button_cancel) %> " onclick='$("update-form-<%= @review.id %>").hide();'/>
</p>
 <%= wikitoolbar_for 'review_comment_' + @review.id.to_s %>
<% end %>

</div>

</div>
<% if @review.issue.journals.length > 0 %>
 <h3>
    <%=  l(:label_comment) %>
  </h3>
<% end %>

<%= render :partial => 'reply', :collection => @review.issue.journals.sort{|a, b| a.id <=> b.id} %>


<% if authorize_for('code_review', 'reply') -%>
<p><%= toggle_link l(:button_reply), "reply_#{@review.id}", :focus => 'reply_comment_' + @review.id.to_s %></p>
<div id="reply_<%= @review.id  %>" style="display:none;" class="box">
<% form_for :reply, @reply, :url => {:action => 'reply', :id => @project, :review_id => @review.id}, :html => {:id => 'message-form'} do |f| %>
  <%= hidden_field_tag :review_id, @review.id %>
  <%= hidden_field :review,  :lock_version%>
  <%= hidden_field :issue,  :lock_version%>
  <% if @allowed_statuses and @allowed_statuses.any? %>
  <p>
      <label>
        <%=h l(:field_status) %>:
      </label>
      <%  # select :review, :status, {l(:label_review_closed) => CodeReview::STATUS_CLOSED, l(:label_review_open) => CodeReview::STATUS_OPEN} %>
<%= select :review, :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %>

  </p>
    <% end %>
<p>
  <%= f.text_area :comment,
                   :cols => 30,
                   :rows => 10,
                   :accesskey => accesskey(:edit),
                   :class => 'wiki-edit',
                   :id => 'reply_comment_' + @review.id.to_s %>
 
</p>
<p>
  <%= submit_to_remote 'apply', l(:button_apply), :update => "show_review_#{@review.id}",
        :url => {:controller => 'code_review', :action => 'reply', :id=>@project}, :method => :post %>
</p>
<%= wikitoolbar_for 'reply_comment_' + @review.id.to_s %>
<% end %>
</div>

<% end %>
</div>
</div>
</div>

<%= javascript_tag("setDraggables();") %>